{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3706a293",
   "metadata": {},
   "source": [
    "------------\n",
    "* 日期：2022-010-12 \\ week05（周三）\n",
    "* 课程：python\n",
    "* 记录人：zhou\n",
    "------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "87d17ffa",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "> 1. 有序的数据结构-字符串\n",
    ">> 1. 字符串的基本概念（回顾）\n",
    ">>> 1. Single quotes: 'allows embedded \"double\" quotes'\n",
    ">>> 2. Double quotes: \"allows embedded 'single' quotes\"\n",
    ">>> 3. Triple quoted:  '''Three single quotes'''\"\"\"Three double quotes\"\"\"\n",
    ">> 2. 字符串的性质和方法\n",
    "> 2. 有序的数据结构-列表"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8efa0fa9",
   "metadata": {},
   "source": [
    "# 1.字符串的性质和方法\n",
    "\n",
    "> 1. 字符串的有序性\n",
    "> 2. 字符串是有长度的\n",
    ">> 1.使用len()检查字符串的长度\n",
    "* 字符串的基础方法（运算法则）\n",
    "> 1. 字符串的取值：str[index]   #str字符串 括号里面是index的取值\n",
    "> 2. 字符串的切片：str[star,stop],stop取不到\n",
    "> 3. 字符串的拼接： +\n",
    "> 4. in检查成员是否存在\n",
    "* 字符串的一般方法（function/Methods 函数/方法）\n",
    "> 1. isdigit()\n",
    "> "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "cf1fc29e",
   "metadata": {},
   "outputs": [],
   "source": [
    "text = \"广州南方学院团委\"   # value\n",
    "\n",
    "#index 0 1 2 3 4 5 6 7 8 9 10 11 ……（相对应）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ee18cafc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a421224c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "bc134aed",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'委'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "436cbb89",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'团'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d4c2b142",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "string index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "Input \u001b[1;32mIn [7]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mtext\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m100\u001b[39;49m\u001b[43m]\u001b[49m\n",
      "\u001b[1;31mIndexError\u001b[0m: string index out of range"
     ]
    }
   ],
   "source": [
    "text[100]   #字符串长度不够100，因此显示错误"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "40751541",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(text)  #len()检查字符串的长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "71c99e3e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0] + text[1] + text[2]   #字符串的拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c76c35d4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0:6]   # 等价于text[:6]     广州南方学院   text[0:6]里的6指的是停止值stop\n",
    "                                 0 1 2 3 4 5 \n",
    "#字符串的切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "c2828c92",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "65a7d518",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'院团'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-3:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "3839eb9d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[:-2]   # 等价于text[0:-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "0558537a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'团委'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-2:]  # 等价于text[-2:0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "282f0315",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院团委广州南方学院团委广州南方学院团委'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 * text"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4c6be617",
   "metadata": {},
   "source": [
    "* in 检查成员对象\n",
    "* count()检查字符串出现的次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "9730110f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"广州\" in text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "b4e307eb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"北京\" in text "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "0fee88c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 * text.count(\"广州\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "74614533",
   "metadata": {},
   "source": [
    "* isdigit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "80da7e40",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19\n",
      "19\n"
     ]
    }
   ],
   "source": [
    "print(19)\n",
    "print(\"19\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "b0626594",
   "metadata": {},
   "outputs": [],
   "source": [
    "age_1=19\n",
    "age_2=\"19\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d21c9f9a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "c8143913",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19\n",
      "19\n"
     ]
    }
   ],
   "source": [
    "print(age_1)\n",
    "print(age_2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "7d9cc3ef",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19 <class 'int'>\n",
      "19 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(age_1,type(age_1))\n",
    "print(age_2,type(age_2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "76362c71",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "38\n"
     ]
    }
   ],
   "source": [
    "# 如果字符串是数值，可以用int转换成真正的数值\n",
    "if age_2.isdigit():\n",
    "    print(age_1 + int(age_2))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a55e080d",
   "metadata": {},
   "source": [
    "# 2.有序的数据结构=列表（List）\n",
    "\n",
    "* 1. 列表的概念和基本性质\n",
    "> 1. Python knows a number of compound data types, used to group together other values. The most versatile is the list, which can be written as a list of comma-separated values (items) between square brackets. Lists might contain items of different types, but usually the items all have the same type.\n",
    "Python知道许多复合数据类型，用于将其他值组合在一起。最通用的是列表，它可以写成方括号之间的逗号分隔值（项目）列表。列表可能包含不同类型的项目，但通常这些项目都具有相同的类型。\n",
    "\n",
    "* 2. 列表一般方法（如何学习）\n",
    "> 1.使用.Tab键查看列表的方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ddecadf9",
   "metadata": {},
   "source": [
    "### 2.1 列表的性质\n",
    "\n",
    "* 和字符串的运算法则完全一致\n",
    "* 注意：字符串是对字符进行操作，列表是对items（元素）进行操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "d03a666c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 列表的形式\n",
    "squares = [1, 4, 9, 16, 25] # 列表里面放数值\n",
    "squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "aaf318a0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares[4]   # 和字符串的运算法则完全一致 取值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "a4227fbc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "4 in squares  # 检查字符是否在字符串里面"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "25ce134f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "13"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares[1] + squares[2]  # 拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "92ad1f37",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Jack\",\"Alex\",\"Marry\",\"Jan\"] # 列表里面放字符串\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "b0a3119d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 18, '李华', 20]"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info = [\"Jack\",18,\"李华\",20]\n",
    "info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "41e05953",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 'Jack', 'Alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares + names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "0420cb62",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2*squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "73f481f6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Alex', 'Marry']"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "b3eef6fc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Jan']"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "3080abf6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Marry']"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取出“Jack”，“Marry”用切片的方法\n",
    "names[:3:2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "03b55959",
   "metadata": {},
   "source": [
    "* 2. 列表一般方法（如何学习）\n",
    "> 1. 增加\n",
    "> 2. 删除\n",
    "> 3. 改\n",
    "> 4.查 ： in\n",
    "* 列表的学习方法（步骤）\n",
    "> 1. 使用.Tab键查看列表的方法\n",
    "> 2. 使用help（查看方法使用规则）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "3c3d8f27",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Jack\",\"Alex\",\"Marry\",\"Jan\"] \n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "57d7bba9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "ed5f4f59",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"Luhua\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "46ca7933",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan', 'Luhua']"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "40abf083",
   "metadata": {},
   "source": [
    "## 课后作业\n",
    "* 列表的方法尝试所以的方法\n",
    "* 总结列表的方法学习心得（表格形式总结）\n",
    "| Syntax      | Description |\n",
    "| ----------- | ----------- |\n",
    "| Header      | Title       |\n",
    "| Paragraph   | Text        |"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10ca35ad",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
